import query from '@dfeidao/atom-nodejs/db/query';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../atom/config';

interface Message {
	productid: string;
	information_template_type: string;
	information_template_status: string;
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:app-manual-check/s006,action_id:' + action_id);
	const { prepare, exec } = query(action_id, session_id, systemid);
	prepare('information_template', ["productid", "information_template_type", "information_template_title", "information_template_status", "information_template_content"], { productid: message.productid, information_template_type: message.information_template_type, information_template_status: message.information_template_status }, 1, 1, [], []);
	const [data] = await exec();
	log('Service end path:app-manual-check/s006,action_id:' + action_id);
	return {
		data
	};
}
